\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{slide}[2023/12/27 slide class]

\RequirePackage{kvoptions}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{beamer}}
\ProcessKeyvalOptions*
\PassOptionsToClass{utf8,9pt}{beamer}
\ProcessOptions*\relax
\LoadClass{beamer}
\RequirePackage{ifthen}
\newif\ifnopause
% beamer 提供了 handout 模式，可以忽略掉所有停顿
\ifthenelse{\equal{\beamer@currentmode}{handout}}{\nopausetrue}{\nopausefalse}

\usetheme{Boadilla}
\usefonttheme{structurebold}
%\setbeamertemplate{background}{\includegraphics[width=\paperwidth,height=\paperheight]{slidebg.png}}
%\ifnopause
  \usecolortheme{beaver}
%\else
%  \usecolortheme{frigatebird}%magpie}%cormorant}
%\fi
%gets rid of bottom navigation bars
\setbeamertemplate{footline}[frame number]{}
%gets rid of bottom navigation symbols
\setbeamertemplate{navigation symbols}{}
%gets rid of footer
%will override 'frame number' instruction above
%comment out to revert to previous/default definitions
\setbeamertemplate{footline}{}
%\setbeamerfont{frametitle}{family=\ttfamily}
% 文字对齐
\RequirePackage{ragged2e}
% https://tex.stackexchange.com/questions/50004/justify-text-inside-itemize-environment-with-beamer-class
% 让 itemize 和 enumerate 环境中文字两端对齐
% vim $(kpsewhere beamerbaselocalstructure.sty)
\renewcommand{\itemize}[1][]{%
  \beamer@ifempty{#1}{}{\def\beamer@defaultospec{#1}}%
  \ifnum \@itemdepth >2\relax\@toodeep\else
    \advance\@itemdepth\@ne
    \beamer@computepref\@itemdepth% sets \beameritemnestingprefix
    \usebeamerfont{itemize/enumerate \beameritemnestingprefix body}%
    \usebeamercolor[fg]{itemize/enumerate \beameritemnestingprefix body}%
    \usebeamertemplate{itemize/enumerate \beameritemnestingprefix body begin}%
    \list
      {\usebeamertemplate{itemize \beameritemnestingprefix item}}
      {\def\makelabel##1{%
          {%
            \hss\llap{{%
                \usebeamerfont*{itemize \beameritemnestingprefix item}%
                \usebeamercolor[fg]{itemize \beameritemnestingprefix item}##1}}%
          }%
        }%
      }
  \fi%
  \beamer@cramped%
  \justifying% NEW
  %\raggedright% ORIGINAL
  \beamer@firstlineitemizeunskip%
}
\renewcommand\enumerate{%
  \ifnum\@enumdepth>2\relax\@toodeep
  \else%
    \advance\@enumdepth\@ne%
    \edef\@enumctr{enum\romannumeral\the\@enumdepth}%
    \advance\@itemdepth\@ne%
  \fi%
  \beamer@computepref\@enumdepth% sets \beameritemnestingprefix
  \edef\beamer@enumtempl{enumerate \beameritemnestingprefix item}%
  \@ifnextchar[{\beamer@@enum@}{\beamer@enum@}}
\def\beamer@@enum@[{\@ifnextchar<{\beamer@enumdefault[}{\beamer@@@enum@[}}
\def\beamer@enumdefault[#1]{\def\beamer@defaultospec{#1}%
  \@ifnextchar[{\beamer@@@enum@}{\beamer@enum@}}
\def\beamer@@@enum@[#1]{% partly copied from enumerate.sty
  \@enLab{}\let\@enThe\@enQmark
  \@enloop#1\@enum@
  \ifx\@enThe\@enQmark\@warning{The counter will not be printed.%
    ^^J\space\@spaces\@spaces\@spaces The label is: \the\@enLab}\fi
  \def\insertenumlabel{\the\@enLab}
  \def\beamer@enumtempl{enumerate mini template}%
  \expandafter\let\csname the\@enumctr\endcsname\@enThe
  \csname c@\@enumctr\endcsname7
  \beamer@enum@}
\def\beamer@enum@{%
  \beamer@computepref\@itemdepth% sets \beameritemnestingprefix
  \usebeamerfont{itemize/enumerate \beameritemnestingprefix body}%
  \usebeamercolor[fg]{itemize/enumerate \beameritemnestingprefix body}%
  \usebeamertemplate{itemize/enumerate \beameritemnestingprefix body begin}%
  \expandafter
    \list
      {\usebeamertemplate{\beamer@enumtempl}}
      {\usecounter\@enumctr%
        \def\makelabel##1{{\hss\llap{{%
                \usebeamerfont*{enumerate \beameritemnestingprefix item}%
                \usebeamercolor[fg]{enumerate \beameritemnestingprefix item}##1}}}}}%
  \beamer@cramped%
  \justifying%
  %\raggedright%
  \beamer@firstlineitemizeunskip%
}


\RequirePackage{graphicx,minted}
%\hypersetup{pdfpagemode=FullScreen}
\hypersetup{unicode=true,psdextra,colorlinks}


% Change standard block colors
% 1- Block title (background and text)
%\setbeamercolor{block title}{bg=blue!80!black, fg=white}
% 2- Block body (background)
%\setbeamercolor{block body}{bg=blue!5}
% Change alert block colors
% 1- Block title (background and text)
%\setbeamercolor{block title alerted}{fg=white, bg=magenta!80!black}
% 2- Block body (background)
%\setbeamercolor{block body alerted}{bg=magenta!5}
% Change example block colors
% 1- Block title (background and text)
%\setbeamercolor{block title example}{fg=white, bg=green!80!black}
% 2- Block body (background)
%\setbeamercolor{block body example}{bg=green!5}
\setbeamersize{description width=0.57cm}

% 在每节之前插入目录
% Do nothing for \section*
\AtBeginSection[] 
{
\begin{frame}%<beamer> %用 <beamer> 的话 handout 模式下目录不显示
\frametitle{目录}
\tableofcontents[currentsection]
\end{frame}
}

% 个人信息，如复用，当然要重新设置
\newcommand{\myemail}{\ttfamily{sc@hsu.edu.cn}}
\newcommand{\myinstitute}{黄山学院数统学院}
\newcommand{\myinstitutelogo}{hsu.jpg}


%------------ bibliography --------------%
\RequirePackage[
  backend=biber,
  hyperref=true,
  doi=true,%style=alphabetic,
  style=gb7714-2015,
  gbnamefmt=lowercase,
]{biblatex}
\renewcommand{\cite}[2][]{\parencite{#2}\ifthenelse{\equal{#1}{}}{}{~#1}}
\addbibresource{../inputs/main.bib}

%------------ 字体设置 ------------%
\RequirePackage{fontspec,xunicode,xltxtra}
%\ifnopause
  \setmainfont{NewComputerModern10}
  \setsansfont{Myriad Pro Light}
%\else
%  \setmainfont{Noto Sans}
%  \setsansfont{Noto Sans}
%\fi
%\setsansfont[BoldFont=Myriad Pro]{Myriad Pro Light}
\setmonofont[Scale=0.9]{DejaVu Sans Mono}
\RequirePackage{xeCJK}
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
%\ifnopause
  %%\setCJKsansfont[BoldFont=Noto Sans CJK SC]{Noto Sans CJK SC Light}
  \setCJKsansfont[
    BoldFont=Noto Sans CJK SC,%FZYaSong-DB-GBK,
    ItalicFont=STKaiti,
  ]{Noto Sans CJK SC Light}
%\else
%  \setCJKsansfont{Noto Sans CJK SC}
%\fi
\setCJKmonofont[Scale=0.9]{FZZhunYuan-M02}
\newcommand\songti{\CJKfontspec{FZShuSong-Z01S}}
\newcommand\heiti{\CJKfontspec{STHeiti}}
\newcommand\xinwei{\CJKfontspec{STXinwei}}
\newcommand\fangsong{\CJKfontspec{STFangsong}}
\newcommand\kaiti{\CJKfontspec{STKaiti}}
\newcommand\lishu{\CJKfontspec{STLiti}}
\newcommand\xingkai{\CJKfontspec{STXingkai}}
\newcommand\youyuan{\CJKfontspec{YouYuan}}
\newcommand\zhunyuan{\CJKfontspec{FZZhunYuan-M02}}
\newcommand\yasongsb{\CJKfontspec{FZYaSong-DB-GBK}}

%\ifnopause\else\AtBeginEnvironment{quote}{\xinwei}\fi

\RequirePackage{url,multicol,extarrows,ulem,cases}
\RequirePackage{pifont} %Pifont package: You can use the optional argument of \item[] to set the marker. With this method we can use the pifont package which provides several symbols that can be used as item markers.
%\RequirePackage{mathtools}
\RequirePackage{unicode-math}
%\ifnopause
  \setmathfont{NewComputerModernMath}
  \setmathfont[range={cal,scr}]{XITS Math}
%\else
%  \setmathfont{Lete Sans Math}
%\fi

%\setlength\multicolsep{\topsep}

%------------ 图形 ------------%
\RequirePackage{graphicx,caption,wrapfig,tikz,pgfplots,indentfirst,xcolor,subcaption}
% wrapfig 在 beamer 中使用时会在奇怪的地方换行，下面是个解决方案
\setlength{\rightskip}{0pt plus 200pt}
\usetikzlibrary{
  cd,arrows,arrows.meta,calc,matrix,
  petri,positioning,decorations,
  decorations.pathreplacing,pgfplots.fillbetween,
  decorations.markings,intersections,
  calligraphy,shapes.geometric,through,angles,quotes,
}
\tikzset{->-/.style={decoration={
  markings,
  mark=at position #1 with {\arrow{>}}},postaction={decorate}
}}
\tikzset{>=Classical TikZ Rightarrow}
\newcommand\circled[1]{\raisebox{1pt}{\tikz[baseline=(char.base)]{\node[circle,draw,inner sep=1pt] (char) {\scriptsize #1};}}}
\usepgfplotslibrary{patchplots}
\usepgfplotslibrary{colormaps}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{width=7cm,compat=newest}

\RequirePackage{zhnumber}
\newcommand{\fangfa}[2][解法]{{\bfseries #1\zhnumber{#2}}：}

\def\appendix{
  \setcounter{section}{0}
  \renewcommand\thesection{\@Alph\c@section}
}


\RequirePackage{multirow}
\RequirePackage[export]{adjustbox}
\RequirePackage{array}   % for \newcolumntype macro
\newcolumntype{L}{>{$}l<{$}} % math-mode version of "l" column type
\newcolumntype{R}{>{$}r<{$}} 
\newcolumntype{C}{>{$}c<{$}} 
\renewcommand{\arraystretch}{1.2}

%https://tex.stackexchange.com/questions/212085/tag-placing-with-amsmath
\makeatletter
\newcommand{\leqnomode}{\tagsleft@true\let\veqno\@@leqno}
\newcommand{\reqnomode}{\tagsleft@false\let\veqno\@@eqno}
\makeatother

% 数学符号
\input{symbols.sty}
\renewcommand\emph[1]{\textbf{\color{orange!50!blue} #1}}
\newcommand\verify{（\textbf{为何？}）}
\newcommand\answer{（\textbf{为何？}）}
%\everymath{\color{teal!70!black}}
%\everydisplay{\color{teal!70!black}}
%\patchcmd{\mathdisplay}{$$}{\begingroup\color{teal!70!black}$$}{}{}
%\patchcmd{\endmathdisplay}{$$}{$$\leavevmode\endgroup}{}{}
\newcommand\essentialexample{通过此例解释，不必再证明}

\counterwithin*{equation}{section}
\counterwithin{theorem}{section}
%\newcounter{theorem}\setcounter{theorem}{0}
\resetcounteronoverlays{theorem}
\newenvironment{sizheng}[1][思政]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
\newcommand{\theoremname}{定理}
% 编号的定理环境可以通过可选参数在头部添加
\renewenvironment{theorem}[1][]{\refstepcounter{theorem}\begin{alertblock}{\theoremname \thetheorem\ifthenelse{\equal{#1}{}}{}{ (#1)}}\justifying}{\end{alertblock}}
% 无编号的定理环境可以通过可选参数替换头部
\newenvironment{theorem*}[1][\theoremname]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
% 问题环境不编号
\newcommand{\questionname}{问题}
\newenvironment{question*}[1][\questionname]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
\newenvironment{assertion*}[1][断言]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
\newcommand{\bonusname}{好处}
\newenvironment{bonus*}[1][\bonusname]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
\newenvironment{warning}[1][注意]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
\newcommand{\propositionname}{命题}
\newenvironment{proposition}[1][]{\refstepcounter{theorem}\begin{alertblock}{\propositionname \thetheorem\ifthenelse{\equal{#1}{}}{}{ (#1)}}\justifying}{\end{alertblock}}
\newenvironment{proposition*}[1][\propositionname]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
\newcommand{\lemmaname}{引理}
\renewenvironment{lemma}[1][]{\refstepcounter{theorem}\begin{alertblock}{\lemmaname \thetheorem\ifthenelse{\equal{#1}{}}{}{ (#1)}}\justifying}{\end{alertblock}}
\newenvironment{lemma*}[1][\lemmaname]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
%\newenvironment{warning}[1][注意]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
\newcommand{\corollaryname}{推论}
\renewenvironment{corollary}[1][]{\refstepcounter{theorem}\begin{alertblock}{\corollaryname \thetheorem\ifthenelse{\equal{#1}{}}{}{ (#1)}}\justifying}{\end{alertblock}}
\newenvironment{corollary*}[1][\corollaryname]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
\newcommand{\observationname}{观察}
\newenvironment{observation}[1][]{\refstepcounter{theorem}\begin{alertblock}{\observationname \thetheorem\ifthenelse{\equal{#1}{}}{}{ (#1)}}\justifying}{\end{alertblock}}
\newenvironment{observation*}[1][\observationname]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
%\newcommand{\promisename}{承诺}
%\newenvironment{promise}[1][\promisename]{\begin{alertblock}{#1}\justifying}{\end{alertblock}}
\newcommand{\examplename}{例}
\renewenvironment{example}[1][]{\refstepcounter{theorem}\begin{exampleblock}{\examplename \thetheorem\ifthenelse{\equal{#1}{}}{}{ (#1)}\justifying}}{\end{exampleblock}}
\newenvironment{example*}[1][\examplename]{\begin{exampleblock}{#1}\justifying}{\end{exampleblock}}
\newcommand{\nonexamplename}{非例}
\newenvironment{nonexample}[1][]{\refstepcounter{theorem}\begin{exampleblock}{\nonexamplename \thetheorem\ifthenelse{\equal{#1}{}}{}{ (#1)}\justifying}}{\end{exampleblock}}
\newenvironment{nonexample*}[1][\nonexamplename]{\begin{exampleblock}{#1}\justifying}{\end{exampleblock}}
\newcommand{\exercisename}{练习}
\newenvironment{exercise}[1][]{\refstepcounter{theorem}\begin{exampleblock}{\exercisename\thetheorem\ifthenelse{\equal{#1}{}}{}{ (#1)}}\justifying}{\end{exampleblock}}
\newenvironment{exercise*}[1][\excercisename]{\begin{exampleblock}{#1}\justifying}{\end{exampleblock}}
\newcommand{\definitionname}{定义}
\renewenvironment{definition}[1][]{\refstepcounter{theorem}\begin{block}{\definitionname\thetheorem\ifthenelse{\equal{#1}{}}{}{ (#1)}}\justifying}{\end{block}}
\newenvironment{definition*}[1][\definitionname]{\begin{block}{#1}\justifying}{\end{block}}
\renewcommand{\proofname}{证明}
%\renewenvironment{proof}[1][\proofname]{\begin{block}{#1}\justifying}{\end{block}}
%添加模式
\renewenvironment{proof}[1][]{\begin{block}{\proofname\ifthenelse{\equal{#1}{}}{}{ (#1)}}\justifying}{\end{block}}
%替换模式
\newenvironment{proof*}[1][\proofname]{\begin{block}{#1}\justifying}{\end{block}}
\newcommand{\solutionname}{解答}
%添加模式
\renewenvironment{solution}[1][]{\begin{block}{\solutionname\ifthenelse{\equal{#1}{}}{}{ (#1)}}\justifying}{\end{block}}
%替换模式
\newenvironment{solution*}[1][\solutionname]{\begin{block}{#1}\justifying}{\end{block}}
\newcommand{\remarkname}{注记}
\newenvironment{remark}[1][]{\refstepcounter{theorem}\begin{block}{\remarkname\thetheorem\ifthenelse{\equal{#1}{}}{}{ (#1)}}\justifying}{\end{block}}
\newenvironment{remark*}[1][\remarkname]{\begin{block}{#1}\justifying}{\end{block}}


\newcommand{\mytitle}{Title}
\newcommand{\mysubtitle}{}
\newcommand{\mybackground}{bg.png}
\RequirePackage{datetime}
\newdateformat{mydate}{\THEYEAR 年 \THEMONTH 月 \THEDAY 日}
% 用于一行两个选项或四个选项
\newcommand{\twochoice}[2]{\par\noindent\parbox{0.5\columnwidth}{#1}%
\parbox{0.5\columnwidth}{#2}}
\newcommand{\fourchoice}[4]{\par\noindent\parbox{0.25\columnwidth}{#1}%
\parbox{0.25\columnwidth}{#2}%
\parbox{0.25\columnwidth}{#3}%
\parbox{0.25\columnwidth}{#4}
}

\AtEndDocument{%
% Add bibliography frame
\begin{frame}%[allowframebreaks]
  {参考文献} 
   % \nocite{*}
\printbibliography
\end{frame}
}

\AtBeginDocument{%
\begin{frame}[plain]
%%%%%%%%%% Title slide code %%%%%%%%%%%
\begin{tikzpicture}[remember picture,overlay]
% Background image
\node[inner sep=0pt] at (current page.center)
{
  \includegraphics[width=\paperwidth]{\mybackground}
};
% Title & Subtitle
\node
[
  above=1.5cm,
    align=center,
    draw=orange,
    left color=orange!50,
    right color=orange!5,
    shading angle=60,
    double,
    double distance=0.1cm,
    inner xsep=15pt,
    inner ysep=10pt, 
    minimum width=0.7\textwidth,
    text width=0.6\textwidth
] (title) at (current page.center)
{
  \ifthenelse{\equal{\mysubtitle}{}}{
    \LARGE \bfseries \mytitle
  }{
    \LARGE \bfseries \mytitle  \\[5pt]
    \small \bfseries \mysubtitle
  }
};
% Author 
%\node[ below=0.5cm] (author) at (title.south){\myauthor};
% Author
\node[below=.5cm] (email) at (title.south) {\small \myemail};
% Author 
\node[ below=0.03cm] (affiliate) at (email.south){\small \myinstitute};
% date
\node[ below=0.03cm] (date) at (affiliate.south){\small \mydate\today};
% Logo
\node[above=1.5cm] at (current page.south)
{
  \includegraphics[width=2cm]{\myinstitutelogo}  
};
\end{tikzpicture}
\end{frame}
% 对齐文本
\justifying
}

